/* -------------------- Check Browser --------------------- */
function browser() {

    var isOpera = !!(window.opera && window.opera.version);  // Opera 8.0+
    var isFirefox = testCSS('MozBoxSizing');                 // FF 0.8+
    var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
    // At least Safari 3+: "[object HTMLElementConstructor]"
    var isChrome = !isSafari && testCSS('WebkitTransform');  // Chrome 1+
    //var isIE = /*@cc_on!@*/false || testCSS('msTransform');  // At least IE6

    function testCSS(prop) {
        return prop in document.documentElement.style;
    }

    if (isOpera) {

        return false;

    } else if (isSafari || isChrome) {

        return true;

    } else {

        return false;

    }

}
/* ---------- Placeholder Fix for IE ---------- */
jQuery(document).ready(function($) {
    $('input, textarea').placeholder();
});

/* ---------- Auto Height texarea ---------- */
jQuery(document).ready(function($) {
    $('textarea').autosize();
});

/* ---------- IE8 list style hack (:nth-child(odd)) ---------- */
jQuery(document).ready(function($) {

    if ($('.messagesList').width()) {

        if (jQuery.browser.version.substring(0, 2) == "8.") {

            $('ul.messagesList li:nth-child(2n+1)').addClass('odd');

        }

    }

});


/* ---------- Check Retina ---------- */
function retina() {

    retinaMode = (window.devicePixelRatio > 1);

    return retinaMode;

}

jQuery(document).ready(function($) {

    /* ---------- Add class .active to current link  ---------- */
    $('ul.main-menu li a').each(function() {
//        alert($(this).attr('active'));
        if ($(this).attr('active') === menuActive) {

            $(this).parent().addClass('active');

        }

    });

    $('ul.main-menu li ul li a').each(function() {

        if ($(this).attr('active') === menuActive) {

            $(this).parent().addClass('active');
            $(this).parent().parent().show();

        }

    });

    /* ---------- Submenu  ---------- */

    $('.dropmenu').click(function(e) {

        e.preventDefault();

        var obj = $(this).parent();
        $(this).parents("ul.main-menu").children("li").each(function() {
            if (obj[0] !== $(this)[0]) {
                $(this).children("ul").slideUp();
            }
        });
        obj.find('ul').slideToggle();
    });

});


/* ---------- Main Menu Open/Close ---------- */
jQuery(document).ready(function($) {

    var startFunctions = true;

    $('#main-menu-toggle').click(function() {

        if ($(this).hasClass('open')) {

            $(this).removeClass('open').addClass('close');

            var span = $('#content').attr('class');
            var spanNum = parseInt(span.replace(/^\D+/g, ''));
            var newSpanNum = spanNum + 2;
            var newSpan = 'span' + newSpanNum;

            $('#content').addClass('full');
            $('.brand').addClass('noBg');
            $('#sidebar-left').hide();

        } else {

            $(this).removeClass('close').addClass('open');

            var span = $('#content').attr('class');
            var spanNum = parseInt(span.replace(/^\D+/g, ''));
            var newSpanNum = spanNum - 2;
            var newSpan = 'span' + newSpanNum;

            $('#content').removeClass('full');
            $('.brand').removeClass('noBg');
            $('#sidebar-left').show();

        }
        $('#Calendar').fullCalendar('render');
    });

});